import java.util.Arrays;
import java.util.Random;

import static java.util.Arrays.binarySearch;
import static java.util.Arrays.spliterator;
class Mythread extends Thread{
    @Override
    public void run() {

    }
}
class MyRunnable implements Runnable{
    @Override
    public void run() {

    }
}

public class TextDemo {
    private static long sum1;
    private static long sum2;
    private static int tem = 0;
    public static void main(String[] args) {
        Thread t = new Thread(()->)
    }

    public static void main3(String[] args) throws InterruptedException {
        Thread t1 = new Thread(){
            @Override
            public void run() {
                while(true){
                    System.out.println(1);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        Thread t2 = new Thread(){
            @Override
            public void run() {
                while(true){
                    System.out.println(2);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t1.start();
        t2.run();
        t1.join();


    }

    public static void main2(String[] args) {
        Thread t1 = new Mythread();
        Thread t2 = new Thread(new MyRunnable());
        Thread t3 = new Thread(){
            @Override
            public void run() {
                super.run();
            }
        };
        Thread t4 = new Thread(new Runnable() {
            @Override
            public void run() {

            }
        });
        Thread t5 = new Thread(()->{
            while(true){
                System.out.println();
            }
        });


    }
    public static void main1(String[] args) throws InterruptedException {
        int[] array = new int[100_0000];
        Random random = new Random();
        for(int i = 0;i<array.length;i++){
            array[i] = random.nextInt(10)%100;
        }
        Thread t1 = new Thread(){
            @Override
            public void run() {
                for(int i =0;i<array.length;i+=2){
                    sum1+=array[i];
                }
            }
        };

        Thread t2 = new Thread(){
            @Override
            public void run() {

                for(int i = 1;i<array.length;i+=2){
                    sum2+=array[i];
                }
            }
        };
        long StartTime = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(sum1+sum2);
        long endTime = System.currentTimeMillis();
        System.out.println(endTime-StartTime);
    }

    public int findTheDistanceValue(int[] arr1, int[] arr2, int d) {
        Arrays.sort(arr2);
        int count = 0;
        for (int x : arr1) {
            int p = binarySearch(arr2, x);
            boolean flag = true;
            //如果不是最后一个那么
            if(p<arr2.length){
                flag&=arr2[p]-x>d;
            }
            //
            if(p-1>=0 && p-1<=arr2.length){
                flag &= x-arr2[p-1]>d;
            }
            count+=flag?1:0;
        }
        return count;
    }
    private int binarySearch(int[] array,int target){
        int left = 0;
        int right = array.length-1;
        if(array[right]<target) {
            return right+1;
        }
        while(left<right){
            int middle = left+(right-left)/2;
            if(array[middle]>target){
                right = middle;
            }else{
                left = middle+1;
            }
        }
        return left;
    }



    private static void print_int(int num) {
        for (int i = 31; i >= 0; i--) {
            System.out.print((num & (1 << i)) == 0 ? "0" : "1");
        }
    }
       private static void selection(int[] nums) {
        if(nums==null || nums.length<2) {
            return;
        }
           for (int i = 0; i < nums.length; i++) {
               int minIndex = i;
               int maxIndex = i;
               for (int j = i + 1; j < nums.length - i; j++) {
                   if (nums[minIndex] > nums[j]) minIndex = j;
                   if (nums[maxIndex] < nums[j]) maxIndex = j;
               }
               if (maxIndex == minIndex) {
                   break;
               }
               swap(nums, i, minIndex);
               if (maxIndex == i) {
                   maxIndex = minIndex;
               }
               int lastIndex = nums.length-i-1;
               swap(nums,lastIndex,maxIndex);
           }
       }
    private static void bubbleSort(int[] array){
            if(array==null || array.length<2) {
                return ;
            }
            int lastIndex = array.length;
            int swapIndex = 0;
            boolean flag = true;
            while(flag){
                flag = false;
                for(int i = 1;i<lastIndex;i++){
                    if(array[i-1]>array[i]){
                        swap(array,i-1,i);
                        flag = true;
                        swapIndex = i;
                    }
                }
                lastIndex = swapIndex;
            }
    }
    //4,7,9,1,0,3,8,2,9,6
    private static void insertSort(int[] nums){
            if(nums==null || nums.length<2){
                return ;
            }
            for(int i = 0;i<nums.length-1;i++){
                int prev = i;
                int currentNumber = nums[i+1];
                while(prev>=0 && nums[prev]>currentNumber){
                    nums[prev+1] = nums[prev];
                    prev--;
                }
                nums[prev+1] = currentNumber;

            }
    }

       private static void swap(int[] array,int x,int y){
           int tem = array[x];
           array[x] = array[y];
           array[y] = tem;
        }

       /* while(num>0){
            System.out.print(num%2);
            num>>=1;
        }*/
    }

